package com.cskaoyan.market.controller;

import com.cskaoyan.market.db.domain.MarketCollect;
import com.cskaoyan.market.service.WxCollectService;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @Author XuFeiLong
 * @DATE: 2023/4/1
 * @TIME: 21:16
 */
@RestController
@RequestMapping("wx/collect")
public class WxCollectController {

    @Autowired
    WxCollectService wxCollectService;

    @GetMapping("list")
    public Object list(byte type, Integer page, Integer limit) {
        List<Map<String, Object>> collectList = wxCollectService.list(type, page, limit);
        return ResponseUtil.okList(collectList);
    }

    @PostMapping("addordelete")
    public Object addordelete(@RequestBody Map<String, Object> collect, HttpServletRequest request) {
        // 将Object-->Integer-->byte
        Integer typePro = (Integer) collect.get("type");
        byte type = typePro.byteValue();
        Integer valueId = (Integer) collect.get("valueId");
        // 如果collect表中有这个商品的valueId则删除,没有则添加
        int code = wxCollectService.addordelete(type, valueId);

        if (code == 200) {
            return ResponseUtil.ok();
        }
        return ResponseUtil.badArgument();

    }
}
